package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {
    private static Teacher[] ts = new Teacher[5];

    public Teacher[] getAllTeacher() {
        return ts;
    }

    public void addTeacher(Teacher teacher) {
        for (int i = 0; i < ts.length; i++) {
            Teacher t = ts[i];
            if (t == null) {
                ts[i] = teacher;
                break;
            }
        }
    }

    public void deleteTeacherById(String id) {
        for (int i = 0; i < ts.length; i++) {
            Teacher t = ts[i];
            if(t!=null&&t.getId().equals(id)){
                ts[i]=null;
                break;
            }
        }
    }

    public void updateTeacher(Teacher t) {
        String id=t.getId();
        for (int i = 0; i < ts.length; i++) {
            Teacher tea = ts[i];
            if (tea!=null&&tea.getId().equals(id)){
                ts[i]=t;
                break;
            }
        }

    }
}
